package com.parkingspace.controller;


import com.parkingspace.entity.Complain;
import com.parkingspace.service.IComplainService;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 投诉表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/complain")
public class ComplainController {

	@Resource
	private IComplainService iComplainService;

	/**
	 * 新建投诉
	 * @param complain 传入内容,用户ID和名称不用传传入token就可以了
	 * @return 返回Boolean
	 */
	@PostMapping("/insertComplain/{token}")
	public ResultVO insertComplain (@PathVariable("token") String token, Complain complain) {
		try {
			Boolean aBoolean = iComplainService.insertComplain(token, complain);
			return new ResultVO(Constants.OPER_SUCCESS,"请求成功!",aBoolean);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE,e.getMessage(),"请求失败!");
		}
	}

	/**
	 * 根据订单ID查询该订单受到的投诉
	 * @param ordereid 传入订单ID
	 * @return 返回List,如何没有返回0
	 */
	@GetMapping("/findByOrderId/{ordereid}")
	public ResultVO findByOrderId (@PathVariable("ordereid") Long ordereid) {
		try {
			List<Complain> byOrderId = iComplainService.findByOrderId(ordereid);
			return new ResultVO(Constants.OPER_SUCCESS,"请求成功!",byOrderId);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_SUCCESS,e.getMessage(),0);
		}
	}

}

